package com.admin.service.impl;

import com.admin.entity.WelcomePage;
import com.admin.mapper.WelcomePageMapper;
import com.admin.service.IWelcomePageService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@Service
public class WelcomePageServiceImpl extends ServiceImpl<WelcomePageMapper, WelcomePage> implements IWelcomePageService {

    @Autowired
    private WelcomePageMapper welcomePageMapper;

    /**
     * 添加欢迎页
     *
     * @param welcomePage
     * @return
     */
    @Override
    public int addHuanYingYe(WelcomePage welcomePage) {
        int insert = welcomePageMapper.insert(welcomePage);
        return insert;
    }

    /**
     * 判断欢迎页面查站点Id 是否存在
     *
     * @param stationId id
     * @return boolean
     */
    @Override
    public boolean findStationId(Integer stationId) {
        QueryWrapper q = new QueryWrapper();
        q.eq("welcome_page_station", stationId);
        WelcomePage welcomePage = welcomePageMapper.selectOne(q);
        if (welcomePage == null) {
            return false;
        }
        return true;
    }

    /**
     * 修改欢迎页面的配置
     *
     * @param welcomePage
     * @return
     */
    @Override
    public boolean updateWelcomePage(WelcomePage welcomePage) {
        System.out.println(welcomePage);
        UpdateWrapper u = new UpdateWrapper();
        u.eq("welcome_page_station", welcomePage.getWelcomePageStation());
        int wp = welcomePageMapper.update(welcomePage, u);
        if (wp == 0) {
            return false;
        }
        return true;
    }

    /**
     * 查询生效的欢迎界面的站点Id
     *
     * @param stationId
     * @return
     */
    @Override
    public WelcomePage queryWelcomePage(Integer stationId) {
        QueryWrapper q = new QueryWrapper();
        q.eq("welcome_page_station", stationId);
        WelcomePage welcomePage = welcomePageMapper.selectOne(q);
        if (welcomePage == null) {
            return null;
        }
        return welcomePage;
    }

    /*
添加站点id
 */
    @Override
    public int insertstationid(int id) {
        WelcomePage w=new WelcomePage();
        w.setWelcomePageStation(id);
        return welcomePageMapper.insert(w);
    }


}
